package com.zhuss.controller.core;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.core.send.ListBySendBo;
import com.zhuss.common.BaseController;
import com.zhuss.core.company.CompanyReadServiceExt;
import com.zhuss.core.user.UserReadServiceExt;
import com.zhuss.enums.EnumUtil;
import com.zhuss.enums.SendType;
import com.zhuss.exception.DzcxException;


/**
 * 发布类型查询 controller
 * @Author zhushanshuo
   @Date 2020-03-31 22:58
 *
 */
  
 
@RestController
@RequestMapping("/send")
public class SendReadController extends BaseController {
	
	@Autowired
	@Qualifier("companyReadServiceExt")
	private CompanyReadServiceExt companyReadServiceExt;
	
	@Autowired
	@Qualifier("userReadServiceExt")
	private UserReadServiceExt userReadServiceExt;
	
	
	/**
	 * 发布类型下拉框
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/sendTypeList")
	public Object sendTypeList() throws DzcxException {
		return EnumUtil.listSelect(SendType.class);
	}
	
	
	/**
	 * 根据类型获取数据
	 * @param bo
	 * @return
	 * @throws DzcxException
	 */
	@ResponseBody
	@RequestMapping("/listBySend")
    public Object listBySend(@RequestBody ListBySendBo bo) throws DzcxException {
		Integer sendType = bo.getSendType();
		if (SendType.单位.sameKey(sendType) || bo.getCompanyId() == null || bo.getCompanyId() == 0l) {
			Object result = companyReadServiceExt.listAll(bo);
			return result;
		} else {
			Object result2 = userReadServiceExt.listByCompany(bo);
			return result2;
		}
    }
	
	
	

	
}
